function e() {
    var e = getApp(), t = e.globalData.accessToken, o = wx.getStorageSync(e.storage.hunyu);
    return console.log("hunyu", o, " accessToken:", t), "3339566d-1b79-4e78-b5c2-21c81cc7cb35" == t ? (wx.setStorageSync(e.storage.meInfo, ""), 
    wx.setStorageSync(e.storage.userInfo, ""), !1) : t && void 0 != t && "" != t && e.globalData.accessToken.length > 0 && void 0 != o && "" != o && o > 0 ? (e.log("已经登录"), 
    !0) : (e.log("未登录"), !1);
}

function t() {
    for (var e = [], t = 0; t < 36; t++) e[t] = "0123456789abcdef".substr(Math.floor(16 * Math.random()), 1);
    return e[14] = "4", e[19] = "0123456789abcdef".substr(3 & e[19] | 8, 1), e[8] = e[13] = e[18] = e[23] = "-", 
    e.join("");
}

var o = require("../component/WxNotificationCenter/WxNotificationCenter.js"), a = (getApp(), 
function(e) {
    return (e = e.toString())[1] ? e : "0" + e;
});

module.exports = {
    formatTime: function(e) {
        var t = e.getFullYear(), o = e.getMonth() + 1, n = e.getDate(), r = e.getHours(), s = e.getMinutes(), i = e.getSeconds();
        return [ t, o, n ].map(a).join("/") + " " + [ r, s, i ].map(a).join(":");
    },
    validatemobile: function(e) {
        return 0 != e.length && 11 == e.length && !!/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/.test(e);
    },
    showToast: function(e) {
        wx.showToast({
            title: e,
            icon: "none"
        });
    },
    showAlert: function(e) {
        wx.showModal({
            title: "提示",
            content: e,
            showCancel: !1,
            confirmColor: getApp().globalData.themeColor,
            success: function(e) {}
        });
    },
    isLogin: e,
    isLoginPage: function() {
        return !!e() || (wx.navigateTo({
            url: "/pages/login/quickLogin/quickLogin"
        }), !1);
    },
    isLoginModal: function() {
        if (e()) return !0;
        var t = getApp();
        return wx.showModal({
            title: "提示",
            content: "请登录之后再操作",
            confirmText: "去登录",
            confirmColor: t.globalData.themeColor,
            success: function(e) {
                e.confirm ? wx.navigateTo({
                    url: "/pages/login/quickLogin/quickLogin"
                }) : e.cancel;
            }
        }), !1;
    },
    isFirstLogin: function() {
        var t = getApp();
        return !(!e() || !t.globalData.firstLogin || (t.globalData.firstLogin = !1, 0));
    },
    logout: function() {
        var e = getApp(), t = wx.getStorageSync(e.storage.openid);
        e.network.post({
            url: e.url.weixinProgramExit,
            params: {
                openId: t
            },
            before: function() {
                wx.showLoading({
                    title: "正在退出"
                });
            },
            success: function(t) {
                wx.hideLoading(), e.util.showToast(t.data.message), 1 == t.data.result && (e.globalData.accessToken = "", 
                wx.setStorageSync(e.storage.accessToken, ""), e.log("退出登录：" + e.globalData.accessToken), 
                o.postNotificationName("logoutSuccess"), setTimeout(function() {
                    wx.navigateBack();
                }, 1200));
            },
            fail: function() {
                wx.hideLoading();
            },
            complete: function() {}
        });
    },
    doLoginWork: function() {
        var e = getApp();
        e.globalData.accessToken = "", wx.setStorageSync(e.storage.accessToken, ""), o.postNotificationName("logoutSuccess");
    },
    getRoleName: function(e) {
        for (var t = "", o = getApp(), a = o.globalData.roleRegisterValues, n = 0; n < a.length; n++) if (e == a[n]) {
            t = o.globalData.roleRegisterNames[n];
            break;
        }
        return t;
    },
    navToUserHome: function(e) {
        wx.navigateTo({
            url: "/pages/userHome/userHome?userAccessToken=" + e
        });
    },
    navToTeamHome: function(e) {
        wx.navigateTo({
            url: "/pages/teamHome/teamHome?teamId=" + e
        });
    },
    callPhone: function(e) {
        if (0 != this.isLoginPage()) {
            var t = getApp();
            t.network.post({
                url: t.url.getUserPhone,
                params: {
                    userAccessToken: e
                },
                before: function() {
                    wx.showLoading({
                        title: "获取号码中"
                    });
                },
                success: function(e) {
                    1 == e.data.result ? wx.makePhoneCall({
                        phoneNumber: e.data.data.phone
                    }) : t.util.showAlert(e.data.message);
                },
                fail: function() {
                    t.util.showToast("获取数据失败");
                },
                complete: function() {
                    wx.hideLoading();
                }
            });
        }
    },
    getQiniuFileName: function(e) {
        var t = new Date();
        return "" + t.getFullYear() + (t.getMonth() + 1) + t.getDate() + t.getHours() + t.getMinutes() + t.getSeconds() + e + Math.floor(100 * Math.random());
    },
    updateQiniuToken: function() {
        var e = getApp();
        e.network.post({
            url: e.url.getQiniuToken,
            params: {},
            before: function() {},
            success: function(t) {
                1 == t.data.result && (e.globalData.qiniuToken = t.data.data.uploadToken);
            },
            fail: function() {},
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    updateUserInfo: function() {
        var e = getApp();
        e.network.post({
            url: e.url.userInfo,
            params: {},
            before: function() {},
            success: function(t) {
                1 == t.data.result && wx.setStorageSync(e.storage.userInfo, t.data.data);
            },
            fail: function() {},
            complete: function() {}
        });
    },
    openAutoOrder: function() {
        var e = getApp(), t = this;
        e.network.post({
            url: e.url.SetWeddingOrderAutoQiangDan,
            params: {
                autoQiangDan: 1
            },
            before: function() {
                wx.showLoading({
                    title: "正在打开自动抢单"
                });
            },
            success: function(e) {
                if (wx.hideLoading(), 1 == e.data.result) wx.showModal({
                    title: "提示",
                    content: e.data.message,
                    showCancel: !1
                }); else if (3 == e.data.result) {
                    var o = e.data;
                    wx.showModal({
                        title: "提示",
                        content: o.message,
                        cancelText: "查看规则",
                        confirmText: "知道了",
                        success: function(e) {
                            e.cancel && wx.navigateTo({
                                url: "/pages/web/web?url=" + o.data.scheduleAccurateUrl
                            });
                        }
                    });
                } else wx.showModal({
                    title: "提示",
                    content: e.data.message,
                    showCancel: !1
                }), t.setData({
                    autoOn: !1
                });
            },
            fail: function() {
                wx.hideLoading(), e.util.showToast("修改失败");
            },
            complete: function() {}
        });
    },
    lastAccessServer: function() {
        var e = getApp();
        e.network.post({
            url: e.url.LastAccessServer,
            params: {
                deviceType: "wechat",
                versionCode: "6666",
                hunyu: wx.getStorageSync(e.storage.hunyu)
            },
            success: function(t) {
                1 == t.data.result && (e.globalData.accessToken = t.data.data.accessToken, wx.setStorageSync(e.storage.accessToken, t.data.data.accessToken), 
                wx.setStorageSync(e.storage.weixinProgramShareInfo, t.data.data.weixinProgramShareInfo), 
                t.data.data.upLevel && (e.globalData.authToken = t.data.data.upLevel, wx.setStorageSync(e.storage.authToken, t.data.data.upLevel)));
            }
        });
    },
    getShareInfo: function(e, o) {
        var a = getApp();
        void 0 == e && (e = a.globalData.commonSharePath), void 0 == o && (o = a.network.url + "appweb/weixinProgramImage.do");
        var n = wx.getStorageSync(a.storage.accessToken), r = t();
        return [ e + "?shareAccessToken=" + n + "&shareKey=" + r + "&fromTo=weixin", o + "?shareAccessToken=" + n + "&shareKey=" + r + "&fromTo=weixin" ];
    },
    openSharePage: function(e) {
        if (void 0 != e.fromTo) {
            var t = "";
            for (var o in e) t = t + o + "=" + e[o] + "&";
            t = t.slice(0, t.length - 1);
            var a = getApp();
            a.network.post({
                url: a.url.OpenWeixinProgram,
                params: {
                    param: t
                },
                before: function() {},
                success: function(e) {},
                fail: function() {},
                complete: function() {}
            });
        }
    },
    isNumber: function(e) {
        return !!/^[0 - 9]*[1-9][0-9]*$/.test(e);
    },
    inviteFromWeixinProgramCodeSceneValue: function(e) {
        var t = getApp(), o = {
            scene: e
        };
        t.network.post({
            url: t.url.GetWeixinProgramCodeSceneValue,
            params: o,
            before: function() {},
            success: function(e) {
                if (1 == e.data.result) {
                    var o = e.data.data.inviteCode;
                    console.log("inviteCode:", o), t.globalData.inviteCode = o;
                }
            },
            fail: function() {},
            complete: function() {}
        });
    },
    getUserInfo: function() {
        var e = getApp();
        1 != wx.getStorageSync(e.storage.hadCommintUserInfo) && wx.login({
            success: function(t) {
                console.log(t.code), wx.getUserInfo({
                    success: function(o) {
                        e.util.commitUserInfo(o, t.code);
                    },
                    fail: function(e) {}
                });
            }
        });
    },
    commitUserInfo: function(e, t) {
        var o = getApp(), a = this;
        o.network.post({
            url: o.url.SubmitWeixinUserInfo,
            params: {
                userInfo: e.userInfo,
                rawData: e.rawData,
                signature: e.signature,
                encryptedData: e.encryptedData,
                iv: e.iv,
                code: t
            },
            before: function() {},
            success: function(e) {
                if (1 == e.data.result) {
                    var t = e.data.openId;
                    t && t.length > 0 && wx.setStorageSync(a.storage.openid, t), wx.setStorageSync(o.storage.hadCommintUserInfo, !0);
                }
            },
            fail: function() {},
            complete: function() {}
        });
    },
    updateWeixinProgramOpen: function(e, t, o) {
        var a = getApp();
        a.network.post({
            url: a.url.weixinProgramOpen,
            params: {
                path: e,
                scene: t,
                query: o
            },
            success: function(e) {}
        });
    },
    getWPDownloadAppInfo: function() {
        var e = getApp(), t = wx.getSystemInfoSync().platform;
        "devtools" == t && (t = "ios");
        var a = {
            type: t
        };
        e.network.post({
            url: e.url.GetWPDownloadAppInfo,
            params: a,
            before: function() {},
            success: function(t) {
                if (1 == t.data.result) {
                    var a = t.data.data.open;
                    e.globalData.appDownOpen = a, 1 == a && (e.globalData.appDownImage = t.data.data.image), 
                    "android" == t.platform && (e.globalData.appDownloadUrl = t.data.data.downloadUrl), 
                    o.postNotificationName("getWPDownloadAppInfoSuccess");
                }
            },
            fail: function() {},
            complete: function() {}
        });
    }
};